<!--title-->
<div class="mnav1">
	<div class="m_nav">
		<div class="nav_left">
			<em class="home_icon"><?=$this->sys_name?></em><span>&nbsp;&gt;&nbsp;</span><font><?=$this->title?></font>
		</div>
	</div>
</div>

<div class="content-table">
<div class="content-table-title"><?=$this->title?></div>
<br />
<?php if($this->msg):?>
<div class="replace"><?=$this->msg?></div>
<br />
<?php endif;?>
<div class="form-edit-task">

<form action="/contracts/edit-pay-plans-submit" method="post" name="form1" onsubmit="submitform(this);return false;">
<input type="button" value="添加回款计划" onclick="window.location.href='/contracts/add-pay-plan2/contract_id/<?=$this->contract_id?>'" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: orange; font-size: 9px">(回款总额需等于合同实际金额：<?=$this->contract_info['contract_value']?>元)</span>
<br><br>
<table border="1" width="100%">
	<tr>
		<th>计划回款日期</th>
		<th>金额</th>
		<th>备注</th>
		<th>发票号</th>
		<th>状态</th>
		<th>操作</th>
	</tr>
	<?php if(!empty($_SESSION['edit-pay-plans'][$this->contract_id])):?>
	<?php foreach($_SESSION['edit-pay-plans'][$this->contract_id] as $id => $val):?>
	<tr>
		<td><?=$val['plan_date']?></td>
		<td><?=$val['plan_value']?></td>
		<td><?=$val['tips']?></td>
		<td><?=$val['invoice']?></td>
		<td><?=$val['status']?"<font color='green'>已认款</font>":"未认款"?></td>
		<td><input type="button" value="删除" onclick="DelPayPlan(<?=$id?>, <?=$this->contract_id?>)" /></td>
	</tr>
	<?php endforeach;?>
	<?php endif;?>
</table>
<br /><br />
<div align="center"><input type="button" class="buttonlong" value="提交" onclick="submitform();return false;" /></div>
<input type="hidden" name="contract_id" value="<?=$this->contract_id?>" />
</form>
</div>
<br/><br/>
</div>

<script>
function DelPayPlan(id, contract_id)
{
	var msg = "确定要删除吗？"; 
	if (confirm(msg)==true){ 
		window.location.href='/contracts/del-pay-plan-from-contract2/id/' + id + '/contract_id/' + contract_id;
	}else{ 
		return false; 
	} 
}

function submitform() 
{
	<?php
	$plan_total = 0;
	$plan_total2 = 0;
	
	if($_SESSION['edit-pay-plans'][$this->contract_id])
	{
		foreach($_SESSION['edit-pay-plans'][$this->contract_id] as $id => $val)
		{
			$plan_total += $val['plan_value'];
			
			if($val['plan_value'] > 0)
			{
				$plan_total2 += $val['plan_value'];
			}
		}
	}
	?>
			
	<?php if(round($plan_total,2) != round($this->contract_info['contract_value'],2) && round($plan_total2,2) != round($this->contract_info['contract_value'],2) && "LEVEL-3" != $_SESSION['identity']['level']):?>
	alert("回款总额需等于合同实际金额：<?=$this->contract_info['contract_value']?>元，请修改回款计划。当前回款总额：" + <?=$plan_total?> + "/" + <?=$plan_total2?>);
	return false;
	<?php endif;?>
	
	form1.submit();
}
</script>
